import java.io.*;
import java.net.Socket;

public class ClientT1 {
    public static void main(String[] args) {
        try {

            Socket socket = new Socket("127.0.0.1",9999);
            ClientThread t = new ClientThread(socket);
            t.start();
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String strIn = "";
            while(true){
                strIn = br.readLine();
                if(strIn.contains("file")){
                    //创建FileOutputStream()对象实例来保存从客户端发送的文件，并将文件写入到对象中
                    FileOutputStream fos = new FileOutputStream(new File("E:\\dd.txt"));
                    byte[] b=new byte[1024];
                    int len;
                    while((len=is.read(b))!=-1){
                        fos.write(b, 0, len);
                    }
                    //5.服务端反馈信息，将信息储存在数据缓冲区中
                    OutputStream os = socket.getOutputStream();
                    os.write("你发送的文件我已经接收".getBytes());
                }else {
                    System.out.println(strIn);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}